package com.zhanglijie.theory.threadpermessage;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

/**
 * @author zhanglijie
 * @version 1.0
 * @since 1.1.0 2022/8/14 0014 19:51
 */
public class Service {
    public static void service(Socket socket) throws IOException {
        System.out.println(Thread.currentThread().getName()+"====> service start......");
        OutputStream outputStream = socket.getOutputStream();
        DataOutputStream dataOutputStream = new DataOutputStream(outputStream);
        dataOutputStream.writeBytes("HTTP/1.0 200 OK\r\n");
        dataOutputStream.writeBytes("Content-type:text/html\r\n");
        dataOutputStream.writeBytes("\r\n");
        dataOutputStream.writeBytes("<html><head><title>mytitle</title></head><body>");
        for (int i = 0; i < 10; i++) {
            dataOutputStream.writeBytes("hello world!!"+i);
            dataOutputStream.flush();
            dataOutputStream.writeBytes("<br/>");
            try {
                Thread.sleep(1000);
            }catch (Exception e){}
        }
        dataOutputStream.writeBytes("</body></html>");
        dataOutputStream.close();
        socket.close();
        System.out.println(Thread.currentThread().getName()+"======>service end");
    }
}
